package springboot.tool;

import org.springframework.stereotype.Component;
import springboot.netty.SimpleServerHandler;

@Component
public class SendMSGToPLC {

    public void sendMSGtoPLC(int countDay,int i){
        if (countDay>256*256*256){
            SimpleServerHandler.DATA[i]=(byte)(countDay/(256*256*256));
            SimpleServerHandler.DATA[i+1]=(byte)((countDay%(256*256*256))/(256*256));
            SimpleServerHandler.DATA[i+2]=(byte)(((countDay%(256*256*256))%(256*256))/(256));
            SimpleServerHandler.DATA[i+3]=(byte)(((countDay%(256*256*256))%(256*256))%(256));
        }else if (countDay>256*256){
            SimpleServerHandler.DATA[i]=0;
            SimpleServerHandler.DATA[i+1]=(byte)(countDay/(256*256));
            SimpleServerHandler.DATA[i+2]=(byte)((countDay%(256*256))/256);
            SimpleServerHandler.DATA[i+3]=(byte)((countDay%(256*256))%256);
        }else if (countDay>256){
            SimpleServerHandler.DATA[i]=0;
            SimpleServerHandler.DATA[i+1]=0;
            SimpleServerHandler.DATA[i+2]=(byte)(countDay/(256));
            SimpleServerHandler.DATA[i+3]=(byte)(countDay%(256));
        }else if (countDay>0){
            SimpleServerHandler.DATA[i]=0;
            SimpleServerHandler.DATA[i+1]=0;
            SimpleServerHandler.DATA[i+2]=0;
            SimpleServerHandler.DATA[i+3]=(byte)(countDay%(256));
        }
    }

}
